package com.colin.controller;

import com.colin.pojo.YouLian;
import com.colin.service.YouLianService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping ("youlian")
public class YouLianController {
    @Autowired
    YouLianService youLianService;

    @RequestMapping ("insert")
    public String add (YouLian y) {
        String path="<a href=\"https://"+y.getDizhi()+"/\">"+y.getName()+"</a>";
        //<a href="https://jx.tmall.com/">京东</a>
        y.setDizhi(path);
        youLianService.insert(y);
        return "forward:/youlian/find";
    }

    @RequestMapping ("find")
    public String add (YouLian y, HttpSession session) {
        //List<YouLian> youlian = youLianService.findYouLian();
        //int size = youLianService.findCount();
        //session.setAttribute("size", size);//友链了多少个
        //session.setAttribute("youlian", youlian);
        return "redirect:/web/tiaoZhuan7";
    }

    @RequestMapping ("delete")
    public String delete (Integer id) {
        youLianService.deleteYouLian(id);
        return "forward:/youlian/find";
    }
}
